﻿Imports BUS
Imports DTO
Imports System.Resources
Imports System.Globalization
Imports System.Reflection
Imports DevComponents.DotNetBar.Design
Imports DevComponents.DotNetBar

Public Class frmMain
    Dim ngon As Integer = NgonNgu.ngon
    ' ' ' 'ok roi 
#Region "Xử Lý Cho Tab Quản Lý Nhân Viên"

    Private Sub btnTimKiemNhanh_QLNV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiemNhanh_QLNV.Click
        ' ' ' tim kiêm theo họ tên, UserName  và so điện thoại 
        Try
            Dim nv As New NhanVienBUS
            DataGridView_QLNV.DataSource = nv.TimKiem(txtTimKiemNhanh_QLNV.Text)
            ' ' '  tìm kiêm theo địa chỉ 
            txtTimKiemNhanh_QLNV.Clear()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Public Sub KiemTraNhanVien()
        If txtQLNV_UserName.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Tên đăng nhập không được để trống")
            Else
                Throw New Exception("Username is not empty")
            End If
        ElseIf txtQLNV_PassWord.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Mật khẩu  không được để trống")
            Else
                Throw New Exception("Password  is not empty")
            End If
        ElseIf txtQLNV_ConfimPass.Text = "" Then

            If ngon = 0 Then
                Throw New Exception("Xác nhận  Mật khẩu không được để trống")
            Else
                Throw New Exception("Confirm Password  is not empty")
            End If
        ElseIf txtQLNV_Fone.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Số điện thoại không được để trống")
            Else
                Throw New Exception("phone number is not empty")
            End If

        ElseIf txtQLNV_FullName.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Họ tên không được để trống")
            Else
                Throw New Exception("Full name is not empty")
            End If

        ElseIf txtQLNV_Address.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Địa chỉ không được để trống")
            Else
                Throw New Exception("Address is not empty")
            End If
        ElseIf txtQLNV_Address.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Địa chỉ không được để trống")
            Else
                Throw New Exception("Address is not empty")
            End If
        ElseIf rdiNam.Checked = False And rdoNu.Checked = False Then


            If ngon = 0 Then
                Throw New Exception("Bạn chưa chọn giới tính")
            Else
                Throw New Exception(" You may select gender")
            End If

          
        End If
            
    End Sub

    Public Sub RefreshTable()
        Dim dt As New DataTable
        Dim nvBus As New NhanVienBUS()
        dt = nvBus.LayNhanVien()

        DataGridView_QLNV.DataSource = dt
        DataGridView_QLNV.Columns(6).Visible = False
    End Sub

    Private Sub tabQuanLynhanVien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabQuanLynhanVien.Click
        RefreshTable()
    End Sub

    Private Sub txtTimKiemNhanh_QLNV_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTimKiemNhanh_QLNV.TextChanged
        Try
            Dim nv As New NhanVienBUS
            DataGridView_QLNV.DataSource = nv.TimKiem(txtTimKiemNhanh_QLNV.Text)
            ' ' '  tìm kiêm theo địa chỉ 

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    ' bị lỗi vì nhân viên chưa bị xóa khỏi CSDl ma chỉ ẩn thôi nen khi thêm giống tên sẽ báo lỗi
    ' nhân vien còn thiếu ngày sinh

    Private Sub btnThemNhanVien_QLNV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemNhanVien_QLNV.Click


        Try
            KiemTraNhanVien()
            Dim nv As New NhanVienDTO
            nv.laytenDN = txtQLNV_UserName.Text
            nv.LayPass = txtQLNV_PassWord.Text
            nv.LayPass_Confirm = txtQLNV_ConfimPass.Text
            nv.LayDiaChi = txtQLNV_Address.Text
            nv.LayTenHo = txtQLNV_FullName.Text
            nv.LaySDT = txtQLNV_Fone.Text
            nv.LayIDNguoiDung = cmbLoai_QLNV.SelectedValue
            If rdiNam.Checked = True Then
                nv.LayGioiTinh = "Nam"
            ElseIf rdoNu.Checked = True Then
                nv.LayGioiTinh = "Nữ"
            Else
                nv.LayGioiTinh = ""
            End If
            ' nv.LayGioiTinh =  txtQLND_GioiTinh.Text()
            ' kiểm tra bên BUS kiểm  tra
            Dim nhanvien As New NhanVienBUS
            nhanvien.ThemNhanVien(nv)
            ' ' ' them xong cập nhật lại dataGridView
            DataGridView_QLNV.DataSource = nhanvien.LayNhanVien()

            ThemThanhCong()
            txtQLNV_UserName.Text = ""
            txtQLNV_PassWord.Text = ""
            txtQLNV_ConfimPass.Text = ""
            txtQLNV_FullName.Text = ""
            txtQLNV_Fone.Text = ""
            txtQLNV_Address.Text = ""
            cmbLoai_QLNV.SelectedIndex = -1
            rdiNam.Checked = False
            rdoNu.Checked = False

        Catch ex As Exception
            If ngon = 1 Then
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If

        End Try


    End Sub

    ' ' ' ' biến này dung f để xóa nhân viên
    Dim xoanhanvien As New NhanVienDTO

    Private Sub btnXoaNhanVien_QLNV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaNhanVien_QLNV.Click

        If DataGridView_QLNV.SelectedRows.Count = 0 Then
            Xoaloi()
            Exit Sub
        End If

        If HoiXoa() = Windows.Forms.DialogResult.Yes Then
            If DataGridView_QLNV.SelectedRows.Count > 0 Then
                For i As Integer = 0 To DataGridView_QLNV.SelectedRows.Count - 1
                    Dim nhanvien As New NhanVienBUS
                    Dim nv As New NhanVienDTO
                    nv.laytenDN = DataGridView_QLNV.SelectedRows(i).Cells(0).Value
                    nhanvien.XoaNhanVien(nv)
                Next
                XoaThanhCong()
                Dim nhanvien1 As New NhanVienBUS
                DataGridView_QLNV.DataSource = nhanvien1.LayNhanVien()
            End If
        End If
    End Sub

    ' ' ' khi chon 1 nhan vien thi thong tin se hien len TextBox 
    Private Sub DataGridView_QLNV_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView_QLNV.SelectionChanged

        ' xóa nhân viên chỉ cần tên đăng nhập là đủ
        ' mới chỉ xóa được 1 nhân viên
        xoanhanvien.laytenDN = DataGridView_QLNV.CurrentRow.Cells(0).Value ' '' tên đăng nhập

        '   xoanhanvien.
        txtQLNV_UserName.Text = ""
        txtQLNV_PassWord.Text = ""
        txtQLNV_ConfimPass.Text = ""
        txtQLNV_FullName.Text = ""
        txtQLNV_Fone.Text = ""
        txtQLNV_Address.Text = ""

        rdiNam.Checked = False
        rdoNu.Checked = False

        ' '' ''' dùng để cập nhật lại thông tin cho nhân viên
        ' ' load tên loại nhân viên
        Dim dt As New DataTable
        Dim loai As New LoaiNguoiDungBUS
        dt = loai.LayLoai()
        cmbLoai_QLNV.DataSource = dt
        cmbLoai_QLNV.DisplayMember = "TenLoaiNguoiDung"
        cmbLoai_QLNV.ValueMember = "idNguoiDung"
        cmbLoai_QLNV.SelectedIndex = -1

        If (DataGridView_QLNV.SelectedRows.Count = 1) Then
            txtQLNV_UserName.Text = DataGridView_QLNV.CurrentRow.Cells(0).Value ' ' '' username
            txtQLNV_PassWord.Text = DataGridView_QLNV.CurrentRow.Cells(1).Value.ToString.Trim ' ' '' pas
            txtQLNV_ConfimPass.Text = DataGridView_QLNV.CurrentRow.Cells(1).Value.ToString.Trim '' ' '' pas
            txtQLNV_Address.Text = DataGridView_QLNV.CurrentRow.Cells(4).Value  ' ' 'Địa chỉ
            txtQLNV_FullName.Text = DataGridView_QLNV.CurrentRow.Cells(2).Value ' ' 'Họ Tên
            txtQLNV_Fone.Text = DataGridView_QLNV.CurrentRow.Cells(3).Value.ToString.Trim   ' SDT

            Dim kt As Integer = DataGridView_QLNV.CurrentRow.Cells(6).Value ' ' ' loại

            If kt = 1 Then
                cmbLoai_QLNV.SelectedIndex = 0
            Else
                cmbLoai_QLNV.SelectedIndex = 1
            End If
            Dim str As String = DataGridView_QLNV.CurrentRow.Cells(5).Value   ' giới tính
            If str = "Nữ" Then
                rdoNu.Checked = True
                nhanviencapnhat.LayGioiTinh = "Nữ"
            Else
                rdiNam.Checked = True
                nhanviencapnhat.LayGioiTinh = "Nam"
            End If
            nhanviencapnhat.laytenDN = DataGridView_QLNV.CurrentRow.Cells(0).Value ' ' '' username

        End If


    End Sub

    Public nhanviencapnhat As New NhanVienDTO

    Private Sub btnCapNhatThongTin_QLNV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapNhatThongTin_QLNV.Click

        If DataGridView_QLNV.SelectedRows.Count = 0 Then
            LoiCapNhat()
            Exit Sub
        End If

        Try
            Dim tam As New NhanVienDTO
            tam.laytenDN = txtQLNV_UserName.Text
            tam.LayPass = txtQLNV_PassWord.Text
            tam.LayPass_Confirm = txtQLNV_ConfimPass.Text
            tam.LayDiaChi = txtQLNV_Address.Text
            tam.LaySDT = txtQLNV_Fone.Text
            tam.LayIDNguoiDung = cmbLoai_QLNV.SelectedValue
            tam.LayTenHo = txtQLNV_FullName.Text
            If rdiNam.Checked = True Then
                tam.LayGioiTinh = "Nam"
            Else
                tam.LayGioiTinh = "Nữ"
            End If
            If nhanviencapnhat.laytenDN <> tam.laytenDN Then
                If ngon = 0 Then
                    MessageBox.Show("Cập nhật thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Else
                    MessageBox.Show("Update failed .", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
                Exit Sub
            End If

            If nhanviencapnhat.LayGioiTinh <> tam.LayGioiTinh Then

                If ngon = 0 Then
                    MessageBox.Show("Cập nhật thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Else
                    MessageBox.Show("Update failed .", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
                Exit Sub
            End If

            Dim nv As New NhanVienBUS
            nv.CapNhatNhanVien(tam)


            If ngon = 0 Then
                MessageBox.Show("Cập nhật thành công.", "Thông Báo", MessageBoxButtons.OK)
            Else
                MessageBox.Show("Update Success .", "Notifications", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If

            RefreshTable()
        Catch ex As Exception
            If ngon = 0 Then
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If

        End Try
    End Sub

    ' ' '' load khach hàng lên commobox

#Region "Sự Kiện KeyPress  "

    ' Không Nhập Số và kí tự Đặc Biệt
    Private Sub txtQLNV_UserName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQLNV_UserName.KeyPress
        XuLiHam.NhapKiTu(sender, e)
    End Sub

    ' Nhập kí tự  nhưng không nhập số
    Private Sub txtQLNV_FullName_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        XuLiHam.KhoangTrang(sender, e)
    End Sub
    ' Nhập Số
    Private Sub txtQLNV_Fone_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtQLNV_Fone.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtTimKiemNhanh_QLNV_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTimKiemNhanh_QLNV.KeyPress
        '   XuLiHam.NhapKiTu(sender, e)
    End Sub

#End Region

#Region "Xử lý Cho Tab Khách Hàng"

    Public Sub LoadYaHoo()
        cmbGocEmail.Items.Clear()
        cmbGocEmail.Items.Add("yahoo.com")
        cmbGocEmail.Items.Add("yahoo.com.vn")
        cmbGocEmail.Items.Add("gmail.com")
        cmbGocEmail.Items.Add("gmail.com.vn")
        cmbGocEmail.Items.Add("hotmail.com")
        cmbGocEmail.Items.Add("hotmail.com.vn")
        cmbGocEmail.SelectedIndex = -1
    End Sub

    Public Sub LoadKhachHang()
        Dim kh As New KhachHangBUS
        Dim dt As New DataTable
        DataGridViewKH.DataSource = kh.LayKhachHang()
        DataGridViewKH.Columns(0).Visible = False
        DataGridViewKH.Columns(6).Visible = False

    End Sub

    Public Sub BoXungKiemTra()
        Dim ngonngu As CultureInfo = culInfoMgr.getCultureinfo
        If ngonngu.Name = "vi-VN" Then
            MessageBox.Show("Thông tin khách hàng không được bỏ trống", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("Customer information is not empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Public Function KiemTaKH() As Boolean

        ' ' ' nen viết da ngon ngũ
        If txtDiaChi_KH.Text = "" Then
            BoXungKiemTra()
            Return False
        End If

        If txtEmail_KH.Text = "" Then
            BoXungKiemTra()
            Return False
        End If

        If txtSDT_KH.Text = "" Then
            BoXungKiemTra()
            Return False
        End If

        If txtTenKhachHang.Text = "" Then
            BoXungKiemTra()
            Return False
        End If

        If txtTenKhachHang.Text = "" Then
            BoXungKiemTra()
            Return False
        End If

        Return True
    End Function

    Private Sub tabKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabKhachHang.Click
        LoadYaHoo()
        LoadKhachHang()
    End Sub

    Private Sub btnThemKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemKhachHang.Click

        If KiemTaKH() = False Then
            Exit Sub
        End If
        Try
            Dim kh As New KhachHangDTO
            kh.LayTenKhachHang = txtTenKhachHang.Text
            kh.LaySoDienThoai = txtSDT_KH.Text

            kh.LayDiaChiKhachHang = txtDiaChi_KH.Text
            kh.layEmail = txtEmail_KH.Text + "@" + cmbGocEmail.Text
            If txtTienNo_KH.Text = "" Then
                kh.LayTongNo = 0
            Else
                kh.LayTongNo = txtTienNo_KH.Text
            End If
            Dim khach As New KhachHangBUS
            khach.ThemKhachHang(kh)
            ThemThanhCong() ' ' thong báo thêm thanh cong
            LoadKhachHang()
        Catch ex As Exception
            If ngon = 0 Then
                MessageBox.Show(ex.Message, "lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        End Try

    End Sub

    Private Sub btnXoaKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaKhachHang.Click

        If DataGridViewKH.SelectedRows.Count = 0 Then
            Xoaloi()
            Exit Sub
        End If

        If HoiXoa() = Windows.Forms.DialogResult.Yes Then
            If DataGridViewKH.SelectedRows.Count > 0 Then
                For i As Integer = 0 To DataGridViewKH.SelectedRows.Count - 1
                    Dim KhachHang As New KhachHangBUS
                    Dim kh As New KhachHangDTO
                    kh.LayIDKhachHang = DataGridViewKH.SelectedRows(i).Cells(0).Value
                    KhachHang.XoaKhachHang(kh)
                Next
                XoaThanhCong()
                LoadKhachHang()
            End If
        End If
    End Sub

    Private Sub btnSuaKhachHang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaKhachHang.Click
        If DataGridViewKH.SelectedRows.Count = 0 Then
            LoiCapNhat()
            Exit Sub
        End If

        Dim kh As New KhachHangDTO
        kh.LayTenKhachHang = DataGridViewKH.SelectedRows(0).Cells(1).Value
        kh.layEmail = txtEmail_KH.Text.Trim + "@" + cmbGocEmail.Text
        kh.LayDiaChiKhachHang = txtDiaChi_KH.Text
        kh.LayTongNo = txtTienNo_KH.Text
        kh.LaySoDienThoai = txtSDT_KH.Text
        kh.LayIDKhachHang = idKH
        Dim khachhang As New KhachHangBUS
        khachhang.CapNhatKH(kh)

        LoadKhachHang()
    End Sub

    Dim idKH As Integer

    Private Sub DataGridViewKH_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewKH.SelectionChanged

        Dim arr(1) As String
        If DataGridViewKH.SelectedRows.Count = 1 Then
            idKH = DataGridViewKH.SelectedRows(0).Cells(0).Value
            txtTenKhachHang.Text = DataGridViewKH.SelectedRows(0).Cells(1).Value
            txtSDT_KH.Text = DataGridViewKH.SelectedRows(0).Cells(2).Value
            txtDiaChi_KH.Text = DataGridViewKH.SelectedRows(0).Cells(3).Value
            Dim str As String = DataGridViewKH.SelectedRows(0).Cells(4).Value
            txtTienNo_KH.Text = DataGridViewKH.SelectedRows(0).Cells(5).Value
            arr = str.Split("@")

            If arr.Length = 1 Then
                txtEmail_KH.Text = arr(0).ToString
                cmbGocEmail.SelectedIndex = 0
                Exit Sub
            End If
            txtEmail_KH.Text = arr(0).ToString().Trim
            cmbGocEmail.Text = arr(1).ToString().Trim

        End If

    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtTenKhachHang.Enabled = True
        txtTenKhachHang.Text = String.Empty
        txtDiaChi_KH.Text = String.Empty
        txtSDT_KH.Text = String.Empty
        txtEmail_KH.Text = String.Empty
        txtTienNo_KH.Text = String.Empty
        cmbGocEmail.SelectedIndex = -1
    End Sub


#End Region

#End Region

#Region "Xử lý Cho Tab Nhập Sách"

    Private Sub tabNhapSach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabNhapSach.Click
        ' ' Load Thông Tin Sách Lên DataGridView 
        LoadSach()

    End Sub

    Private Sub btnThemSachCu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemSachCu.Click
        Dim sachbus As New SachBUS
        Dim frm = New frmThemSachCu(Me.culInfoMgr)
        frm.ShowDialog()
        DataGridView_Sach.DataSource = sachbus.LaySach()
    End Sub

    ' ' 'kiem tra không cho control rỗng
    Public Sub KiemTraSach()

        If txtTenSach_NhapSach.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Tên sách không được để trống")
            Else
                Throw New Exception("Name Book í not emty")
            End If
        End If

        If cmbTheLoai_NhapSach.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Thể loại không được để trống.")
            Else
                Throw New Exception("Category is not empty")
            End If
        End If

        If cmbtacGia_NhapSach.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Tên tác giả không được để trống.")
            Else
                Throw New Exception("Author name is not empty")
            End If
        End If

        If txtSoLuong_NhapSach.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Số lượng không được để trống.")
            Else
                Throw New Exception("Quantity is not empty ")
            End If
        End If

        If txtDonGia_NhapSach.Text = "" Then
            If ngon = 0 Then
                Throw New Exception("Đơn giá không được để trống.")
            Else
                Throw New Exception("Price is not empty")
            End If
        End If

    End Sub

    ' khi nhập thì xóa các giá trị trên control trừ cái ngày
    Public Sub ClearNhapSach()
        txtTenSach_NhapSach.Text = String.Empty
        cmbtacGia_NhapSach.SelectedIndex = -1
        cmbTheLoai_NhapSach.SelectedIndex = -1
        txtSoLuong_NhapSach.Text = String.Empty
        txtDonGia_NhapSach.Text = String.Empty
    End Sub

    Private Sub btnNhapSach_NhapSach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNhapSach_NhapSach.Click

        Try
            KiemTraSach()
            Dim sach As New SachDTO
            'Dim cts As New ChiTietSachDTO
            sach.LayTenSach = txtTenSach_NhapSach.Text
            sach.LayIDTheLoai = Integer.Parse(cmbTheLoai_NhapSach.SelectedValue)
            sach.LayGiaSach = txtDonGia_NhapSach.Text
            sach.LayNgayNhap = DateTimeInput_NhapSach.Value.Date
            sach.LaySoLuong = txtSoLuong_NhapSach.Text
            sach.layTacGia = cmbtacGia_NhapSach.SelectedValue

            Dim ns As New SachBUS
            Dim ct As New ChiTietSachDTO
            ct.laytonDau = txtSoLuong_NhapSach.Text
            ct.LayToncuoi = txtSoLuong_NhapSach.Text
            ns.NhapSach(sach, ct)
            ClearNhapSach()

            LoadSach()
            If ngon = 0 Then
                MessageBox.Show("Thêm Sách Thành công.", "Thông Báo", MessageBoxButtons.OK)
            Else
                MessageBox.Show("Add Success.", "Notifications", MessageBoxButtons.OK)
            End If
        Catch ex As Exception
            If ngon = 0 Then
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        End Try
    End Sub

    ' ' '  dung de cập nhat sach
    Dim idSach As Integer
    Public Shared suasach As SachDTO
    Public Shared loaisua As Integer
    Public Shared tentacgia As String
    Public Shared tentheloai As String


    Private Sub DataGridView_Sach_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView_Sach.SelectionChanged
        ' ' ' sữa thông tin của 1 quyển sách
        If DataGridView_Sach.SelectedRows.Count = 1 Then
            suasach = New SachDTO
            loaisua = 1

            txtTenSach_NhapSach.Text = DataGridView_Sach.SelectedRows(0).Cells(0).Value.ToString() ' '  ten sach
            cmbtacGia_NhapSach.Text = DataGridView_Sach.SelectedRows(0).Cells(1).Value.ToString() ' ' 'ten tác giả
            txtDonGia_NhapSach.Text = DataGridView_Sach.SelectedRows(0).Cells(3).Value.ToString() ' 'don gia
            DateTimeInput_NhapSach.Value = DataGridView_Sach.SelectedRows(0).Cells(2).Value.date() ' ' ' ngay nhap
            txtSoLuong_NhapSach.Text = DataGridView_Sach.SelectedRows(0).Cells(4).Value.ToString()
            cmbTheLoai_NhapSach.Text = DataGridView_Sach.SelectedRows(0).Cells(5).Value.ToString() ' ' the loai
            idSach = DataGridView_Sach.SelectedRows(0).Cells(6).Value

            suasach.LayGiaSach = DataGridView_Sach.SelectedRows(0).Cells(3).Value  ''''gia sach

            suasach.LayIdSach = DataGridView_Sach.SelectedRows(0).Cells(6).Value ' idsach
            suasach.LayTenSach = DataGridView_Sach.SelectedRows(0).Cells(0).Value ' ' 'Ten Sach

            suasach.LayIDTheLoai = cmbTheLoai_NhapSach.SelectedValue ' ''idtheloai
            tentheloai = DataGridView_Sach.SelectedRows(0).Cells(5).Value.ToString()  ''''gia sach

            suasach.layTacGia = cmbtacGia_NhapSach.SelectedValue ' ' idTacgia
            tentacgia = DataGridView_Sach.SelectedRows(0).Cells(1).Value  ''''gia sach


        End If

    End Sub

    Private Sub btnXoaSach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaSach.Click

        If DataGridView_Sach.SelectedRows.Count = 0 Then
            Xoaloi()
            Exit Sub
        End If
        Try
            If HoiXoa() = Windows.Forms.DialogResult.Yes Then
                If (DataGridView_Sach.SelectedRows.Count > 0) Then
                    For i = 0 To DataGridView_Sach.SelectedRows.Count - 1
                        Dim sach As New SachDTO
                        Dim s As New SachBUS
                        sach.LayIdSach = DataGridView_Sach.SelectedRows(i).Cells(6).Value
                        s.XoaSach(sach)
                    Next

                    Dim s1 As New SachBUS
                    DataGridView_Sach.DataSource = s1.LaySach()
                    XoaThanhCong()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnSuaSach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaSach.Click

        If DataGridView_Sach.SelectedRows.Count = 0 Then
            LoiCapNhat()
            Exit Sub
        End If

        Try
            Dim sach As New SachDTO
            sach.LayTenSach = txtTenSach_NhapSach.Text
            sach.layTacGia = cmbtacGia_NhapSach.SelectedValue
            sach.LaySoLuong = txtSoLuong_NhapSach.Text
            sach.LayGiaSach = txtDonGia_NhapSach.Text
            sach.LayIDTheLoai = cmbTheLoai_NhapSach.SelectedValue
            sach.LayNgayNhap = DateTimeInput_NhapSach.Value
            sach.LayIdSach = idSach
            Dim s As New SachBUS
            s.CapNhat(sach)
            ClearNhapSach()
            LoadSach()
        Catch ex As Exception

        End Try

    End Sub

    Private Sub btnThemTheLoai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemTheLoai.Click

        Dim frm As New frmTheLoai(Me.culInfoMgr)
        frm.ShowDialog()

        Dim dt As New DataTable
        dt = LoadTheLoai()
        cmbTheLoai_NhapSach.DataSource = dt
        cmbTheLoai_NhapSach.DisplayMember = "TenTheLoai"
        cmbTheLoai_NhapSach.ValueMember = "idTheLoai"
        cmbTheLoai_NhapSach.SelectedIndex = -1
    End Sub

    Private Sub btnThemTacGia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemTacGia.Click

        Dim frm As New frmTacGia(Me.culInfoMgr)
        frm.ShowDialog()

        ' ' ' hiển thị lại tác giả vừa thêm

        Dim dt As New DataTable
        dt = LoadTacGia()
        cmbtacGia_NhapSach.DataSource = dt
        cmbtacGia_NhapSach.DisplayMember = "TenTacGia"
        cmbtacGia_NhapSach.ValueMember = "idTacGia"
        cmbtacGia_NhapSach.SelectedIndex = -1

    End Sub

    Public Sub LoadSachTraCuu()
        Dim dt As New DataTable
        Dim sach As New SachBUS
        dt = sach.LaySach()
        DataGridView.DataSource = dt
        dt = sach.LaySach()
        '       DataGridView.Columns(6).Visible = True
    End Sub

    Public Sub LoadSach()
        Dim dt As New DataTable
        Dim sach As New SachBUS
        dt = sach.LaySach()
        DataGridView_Sach.DataSource = dt


        ' ' ' load tên giả lên CommoBox 
        dt = LoadTacGia()
        cmbtacGia_NhapSach.DataSource = dt
        cmbtacGia_NhapSach.DisplayMember = "TenTacGia"
        cmbtacGia_NhapSach.ValueMember = "idTacGia"
        cmbtacGia_NhapSach.SelectedIndex = -1

        ' ' '' Load thể Loại len CommoBox

        dt = LoadTheLoai()
        cmbTheLoai_NhapSach.DataSource = dt
        cmbTheLoai_NhapSach.DisplayMember = "TenTheLoai"
        cmbTheLoai_NhapSach.ValueMember = "idTheLoai"
        cmbTheLoai_NhapSach.SelectedIndex = -1

        ' ' ' ẩn id sách đi
        DataGridView_Sach.Columns(6).Visible = False
    End Sub

    Public Function LoadTheLoai() As DataTable
        Dim dt As New DataTable
        Dim tl As New TheLoaiBUS
        dt = tl.LayTheLoai()
        Return dt
    End Function

    Public Function LoadTacGia() As DataTable
        Dim dt As New DataTable
        Dim tg As New TacGiaBUS
        dt = tg.LayTacGia()
        Return dt
    End Function

#Region "Sự Kiện KeyPress  "

    'Private Sub txttacGia_NhapSach_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txttacGia_NhapSach.KeyPress, txtTheLoai_NhapSach.KeyPress
    '    XuLiHam.KhoangTrang(sender, e)
    'End Sub

    Private Sub txtTheLoai_NhapSach_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        XuLiHam.KhoangTrang(sender, e)
    End Sub

    Private Sub txtSoLuong_NhapSach_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoLuong_NhapSach.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtDonGia_NhapSach_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDonGia_NhapSach.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

#End Region


#End Region

#Region "tab Qui Định"

    Private Sub tabQuyDinh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabQuyDinh.Click

        LayQuyDinh()
    End Sub

    Public Sub LayQuyDinh()
        Dim qd As New QuyDinhBUS
        Dim dt As New DataTable
        dt = qd.LayQuiDinh()

        txtSLNhapSach_QD.Text = dt.Rows(0).ItemArray(1).ToString()
        txtNhapDauSach_QD.Text = dt.Rows(0).ItemArray(2).ToString()
        txtTienNoToiDa_QD.Text = dt.Rows(0).ItemArray(3).ToString()
        txtLuongTonDauSach_QD.Text = dt.Rows(0).ItemArray(4).ToString()

    End Sub

    Private Sub btnQuiDinh_ThayDoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuiDinh_ThayDoi.Click

        Try
            Dim qd As New QuyDinhDTO
            Dim qui As New QuyDinhBUS
            qd.laySoLuongNhapMin = txtSLNhapSach_QD.Text
            qd.LaySoLuongTonMin = txtNhapDauSach_QD.Text
            qd.LayNoToiDa = txtTienNoToiDa_QD.Text
            qd.LayLuongTonSauKhiBan = txtLuongTonDauSach_QD.Text
            qui.ThayDoiQuiDinh(qd)

            ThayDoiThanhCong()
            LayQuyDinh()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Public Sub ThayDoiThanhCong()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Thay Đổi Thành Công.", "Thông Báo", MessageBoxButtons.OK)
        Else
            MessageBox.Show("Changes Success.", "Success", MessageBoxButtons.OK)
        End If
    End Sub

    Private Sub btnQuiDinh_MacDinh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuiDinh_MacDinh.Click
        Try
            Dim qui As New QuyDinhBUS
            qui.ThayDoiMacDinh()

            ThayDoiThanhCong()
            LayQuyDinh()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try


    End Sub


    Private Sub txtSLNhapSach_QD_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSLNhapSach_QD.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtNhapDauSach_QD_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNhapDauSach_QD.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtTienNoToiDa_QD_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTienNoToiDa_QD.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtLuongTonDauSach_QD_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLuongTonDauSach_QD.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub


#End Region

#Region "Xử lý Cho Tab Lập Hóa Đơn"

    Dim flag As Boolean = False
    Dim makh, mahd As Integer

    Public Sub LoadChiTietHoaDon()
        Dim chitiet As New ChiTietHoaDonBUS
        Dim dtct As New DataTable
        dtct = chitiet.LayChiTiet()
        DataGridView_Chitiethoadon.DataSource = dtct ' ' ' 'hiện thông tin lên DataGridView_Chitiethoadon
        DataGridView_Chitiethoadon.Columns(3).Visible = False  ' ' ' ' ' ẩn cột id sách 
        ' ' ' load tên sách lên CommoBox 
    End Sub

    Private Sub tabLapHoaDon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabLapHoaDon.Click
        ' ' Load hóa Đơn lên DataGridView
        btnThemChiTiet_HoaDon.Enabled = False
        Try
            Dim dt As New DataTable
            Dim hd As New HoaDonBUS
            dt = hd.LayHoaDon()
            DataGridView_lapHoaDon.DataSource = dt
            DataGridView_lapHoaDon.Columns(1).Visible = False  ' ' ' ' ' ẩn cột id khách hàng  

            LoadChiTietHoaDon()  ' ' ' 'hiện thông tin lên DataGridView_Chitiethoadon

            Dim sach As New SachBUS
            dt = sach.LaySach()
            cmbTenSach_LapHoaDon.DataSource = dt
            cmbTenSach_LapHoaDon.DisplayMember = "TenSach"
            cmbTenSach_LapHoaDon.ValueMember = "idSach"

            cmbLayGia_HoaDon.DataSource = dt
            cmbLayGia_HoaDon.DisplayMember = "TenSach"
            cmbLayGia_HoaDon.ValueMember = "idSach"

            Dim kh As New DataTable
            kh = LoadKhacHang()
            cmbTenKhachHang_HoaDon.DataSource = kh
            cmbTenKhachHang_HoaDon.DisplayMember = "TenKhachHang"
            cmbTenKhachHang_HoaDon.ValueMember = "idKhachHang"

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub DataGridView_lapHoaDon_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView_lapHoaDon.SelectionChanged

        If DataGridView_lapHoaDon.SelectedRows.Count = 1 Then

            Try
                Dim khDTO As New KhachHangDTO
                Dim khaBUS As New KhachHangBUS
                Dim cthdDTO As New ChiTietHoaDonDTO
                Dim cthdBUS As New ChiTietHoaDonBUS
                Dim ctsachDTO As New SachDTO
                Dim ctsachBUS As New SachBUS
                khDTO.LayIDKhachHang = DataGridView_lapHoaDon.SelectedRows(0).Cells(1).Value ' ' 'id Khách hàng

                Dim dt As New DataTable
                dt = khaBUS.LayTenKhachHang(khDTO)
                cmbTenKhachHang_HoaDon.Text = dt(0)("TenKhachHang")
                DateTime_LapHoaDon.Value = DataGridView_lapHoaDon.SelectedRows(0).Cells(3).Value ' ' 'ngày lập hóa đơn
                cthdDTO.LayIDHoaDon = DataGridView_lapHoaDon.SelectedRows(0).Cells(0).Value ' ' 'ngày lập hóa đơn

                Dim ct As New DataTable
                ct = cthdBUS.LayChiTietHoaDon(cthdDTO)
                DataGridView_Chitiethoadon.DataSource = ct ' ' ' 'hiện thông tin lên DataGridView_Chitiethoadon

                txtDonGia_LapHoaDon.Text = ct(0)("DonGiaBan")
                txtSoLuong_LapHoaDon.Text = ct(0)("SoLuong")
                ctsachDTO.LayIdSach = ct(0)("idSach")

                Dim cts As New DataTable
                cts = ctsachBUS.LayTenSach(ctsachDTO)

                cmbTenSach_LapHoaDon.Text = cts(0)("TenSach")
            Catch ex As Exception

            End Try

        End If

    End Sub

    ' có nên dung thằng này không  vì bị trùng lập  nợ khách hàng * 2

    Private Sub btnThemChiTiet_HoaDon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemChiTiet_HoaDon.Click

        Try
            If flag = True Then
                Dim hd As New HoaDonDTO
                Dim hoa As New HoaDonBUS

                Dim kh As New KhachHangDTO
                Dim khach As New KhachHangBUS

                kh.LayIDKhachHang = makh
                hd.LayIDHoaDon = mahd
                Dim cthd As New ChiTietHoaDonDTO
                Dim ChiTietHD As New ChiTietHoaDonBUS

                Dim dt As New DataTable
                Dim kq As New DataTable
                dt = khach.LayTenKhachHang(kh) ' ' ' loi o day
                '   DataGridViewX1.DataSource = dt

                Dim no As Integer = dt.Rows(0).ItemArray(5).ToString()

                kq = hoa.IDHoaDon(hd)

                cthd.LayIDHoaDon = kq.Rows(0).ItemArray(0).ToString()
                cthd.LayIDSach = cmbTenSach_LapHoaDon.SelectedValue
                cthd.LayDonGiaBan = txtDonGia_LapHoaDon.Text
                cthd.LaySoLuong = txtSoLuong_LapHoaDon.Text
                ChiTietHD.ThemChiTietHoaDon(cthd)
                ' ' ' ' cập nhật lại nợ khách hành
                Dim sl As Integer = no + (txtDonGia_LapHoaDon.Text * txtSoLuong_LapHoaDon.Text)
                khach.UpDateNo(kh, sl)
                ThemThanhCong()
                LoadChiTietHoaDon()
            Else
                If ngon = 0 Then
                    MessageBox.Show("Bạn phải lập hóa đơn trước khi nhập chi tiết hóa đơn", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Else
                    MessageBox.Show("You have to enter billing information before the bill", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            End If
        Catch ex As Exception

        End Try

    End Sub

    Private Sub btnThemHoaDon_LapHoaDon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemHoaDon_LapHoaDon.Click

        Try
            Dim kh As New KhachHangDTO
            Dim KHBUS As New KhachHangBUS
            Dim qui As New QuyDinhBUS
            Dim cthd As New ChiTietHoaDonDTO
            Dim cts As New ChiTietSachDTO
            Dim chitiethoadon As New ChiTietHoaDonBUS


            ' phan hoa don
            Dim hoadon As New HoaDonBUS
            Dim hd As New HoaDonDTO
            hd.LayUserName = lblHienThiTen.Text
            hd.LayNgayLapHoaDon = DateTime_LapHoaDon.Value
            '     hd.LayThanhToan = Integer.Parse(txtthanhToan.Text) ' ' 'cái này T mới Them
            hd.layIDKhacHang = cmbTenKhachHang_HoaDon.SelectedValue

            ' ' ' lay ton cuoi 
            Dim ct As New DataTable
            cts.LayIDSach = cmbTenSach_LapHoaDon.SelectedValue
            Dim chitietsach As New ChiTietSachBUS
            ct = chitietsach.LayTonCuoi(cts)
            Dim toncuoi As Integer = Integer.Parse(ct.Rows(0).ItemArray(2).ToString())
            Dim sl As Integer = toncuoi - txtSoLuong_LapHoaDon.Text


            ' ' '  lấy nợ khác hàng 
            kh.LayIDKhachHang = cmbTenKhachHang_HoaDon.SelectedValue
            Dim tn As New DataTable
            tn = KHBUS.LayTenKhachHang(kh)

            Dim no As Integer
            no = Integer.Parse(tn.Rows(0).ItemArray(5).ToString())

            cthd.LayDonGiaBan = txtDonGia_LapHoaDon.Text
            cthd.LaySoLuong = txtSoLuong_LapHoaDon.Text
            cthd.LayIDSach = cmbTenSach_LapHoaDon.SelectedValue


            Dim qd As New DataTable
            qd = qui.LayQuiDinh()
            Dim notoida As Integer = Integer.Parse(qd.Rows(0).ItemArray(3).ToString)
            Dim sachtonsaukhiban As Integer = Integer.Parse(qd.Rows(0).ItemArray(4).ToString())

            If (no + (txtSoLuong_LapHoaDon.Text * txtDonGia_LapHoaDon.Text) < notoida And sl > sachtonsaukhiban) Then
                hoadon.ThemHoaDon(hd, cthd)
                Dim nomoi As Integer = no + (txtSoLuong_LapHoaDon.Text * txtDonGia_LapHoaDon.Text)
                KHBUS.UpDateNo(kh, nomoi)

                Dim kq As New DataTable
                kq = hoadon.IDHoaDon(hd)
                flag = True
                mahd = Integer.Parse(kq.Rows(0).ItemArray(0).ToString)
                makh = Integer.Parse(kq.Rows(0).ItemArray(1).ToString)
                chitietsach.CapNhatChiTietSach(cts, sl)

                DataGridView_lapHoaDon.DataSource = hoadon.LayHoaDon()

                ' ' '' cap nhật lại số lượng 
                Dim s As New SachDTO
                s.LayIdSach = cthd.LayIDSach
                Dim sach As New SachBUS
                Dim slsach As Integer = sach.SoLuong(s)
                s.LaySoLuong = slsach - txtSoLuong_LapHoaDon.Text
                sach.CapNhatSoLuong(s)
                ThemThanhCong()
                btnThemHoaDon_LapHoaDon.Enabled = False
                btnThemChiTiet_HoaDon.Enabled = True

            Else

                If ngon = 0 Then
                    MessageBox.Show("Khách hàng nợ quá nhiều", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Else
                    MessageBox.Show("Debt customer too much", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If

            End If

        Catch ex As Exception

        End Try

    End Sub


    Private Sub cmbLayGia_HoaDon_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLayGia_HoaDon.TextChanged
        Dim idsach As New SachDTO
        Dim sach As New SachBUS

        Dim theloai As New TheLoaiDTO
        Dim theloaiBUS As New TheLoaiBUS

        Dim sachBus As New SachBUS

        idsach.LayIdSach = cmbTenSach_LapHoaDon.SelectedValue

        Dim dt As New DataTable
        dt = sachBus.LayTenSach(idsach)

        theloai.LayIdTheLoai = dt(0)("idTheLoai")
        Dim dt1 As New DataTable
        dt1 = theloaiBUS.LayTheLoaiTheoMa(theloai)
        cmbTheLoai_LapHoaDon.DataSource = dt1
        cmbTheLoai_LapHoaDon.DisplayMember = "TenTheLoai"
        cmbTheLoai_LapHoaDon.ValueMember = "idTheLoai"

        idsach.LayIdSach = cmbTenSach_LapHoaDon.SelectedValue
        txtDonGia_LapHoaDon.Text = sach.LayGia(idsach)

    End Sub

    Public Function LoadKhacHang() As DataTable
        '    cmbTenKhachHang_HoaDon.Items.Clear()
        Dim dt As New DataTable
        Dim kh As New KhachHangBUS
        dt = kh.LayKhachHang()
        Return dt
    End Function

    Private Sub btnXoaHoaDon_LapHoaDon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaHoaDon_LapHoaDon.Click

        If DataGridView_lapHoaDon.SelectedRows.Count = 0 Then
            Xoaloi()
            Exit Sub
        End If

        If HoiXoa() = Windows.Forms.DialogResult.Yes Then
            If (DataGridView_lapHoaDon.SelectedRows.Count > 0) Then

                Dim hdBUS As New HoaDonBUS
                For i As Integer = 0 To DataGridView_lapHoaDon.SelectedRows.Count - 1 Step +1
                    Dim hd As New HoaDonDTO
                    Dim chi1 As New ChiTietHoaDonBUS
                    hd.LayIDHoaDon = DataGridView_lapHoaDon.SelectedRows(i).Cells(0).Value.ToString()
                    hdBUS.XoaHoaDon(hd)
                    chi1.updateChitietHD(hd)
                Next

                XoaThanhCong()
                DataGridView_lapHoaDon.DataSource = hdBUS.LayHoaDon()

                Dim chi As New ChiTietHoaDonBUS
                '  DataGridView_Chitiethoadon.DataSource = chi.RefreshHoaDon()
                DataGridView_Chitiethoadon.DataSource = Nothing
            End If
        End If

    End Sub


    ' ' ' ' SuaHoaDon chua viet nua ne
    Private Sub btnSuaHoaDon_LapHoaDon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSuaHoaDon_LapHoaDon.Click

        If DataGridView_lapHoaDon.SelectedRows.Count = 0 Then
            LoiCapNhat()
            Exit Sub
        End If

    End Sub

    Private Sub cmbTenKhachHang_HoaDon_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbTenKhachHang_HoaDon.TextChanged
        btnThemHoaDon_LapHoaDon.Enabled = True
        btnThemChiTiet_HoaDon.Enabled = False
    End Sub

#Region "Sự Kiện KeyPress  "
    ' ' 'bỏ roi
    'Private Sub txtTenKhachHang_LapHoaDon_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTenKhachHang_LapHoaDon.KeyPress
    '    XuLiHam.KhoangTrang(sender, e)
    'End Sub

    'Private Sub txtSoDienThoai_LapHoaDon_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoDienThoai_LapHoaDon.KeyPress
    '    XuLiHam.ChiNhapSo(sender, e)
    'End Sub

    Private Sub txtTheLoai_LapHoaDon_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        XuLiHam.KhoangTrang(sender, e)
    End Sub

    Private Sub txtSoLuong_LapHoaDon_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoLuong_LapHoaDon.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtDonGia_LapHoaDon_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDonGia_LapHoaDon.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

#End Region

#Region ""


#End Region

#End Region

#Region "Xử lý Cho Tab Lập Phiếu Thu"

    Private Sub cmbLayNo_PhieuThu_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLayNo_PhieuThu.TextChanged

    End Sub

    Public Sub LoadKhachHangNo()
        Dim kh As New KhachHangBUS
        Dim kq As New DataTable

        kq = kh.LayKhachHangNo()
        DataGridViewKhachHang_PhieuThu.DataSource = kq
        DataGridViewKhachHang_PhieuThu.Columns(0).Visible = False
        DataGridViewKhachHang_PhieuThu.Columns(6).Visible = False

    End Sub

    Public Sub LoadPhieuThu()
        Dim dt As New DataTable
        Dim p As New PhieuThuBUS
        dt = p.LoadPhieuThu()
        DataGridViewPhieuThu_PhieuThu.DataSource = dt
        DataGridViewPhieuThu_PhieuThu.Columns(1).Visible = False
    End Sub

    Private Sub tabLapPhieuThu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabLapPhieuThu.Click
        LoadKhachHangNo()
        LoadPhieuThu()
        cmbTenKhacHang_PhieuThu.DataSource = LoadKhacHang()
        cmbTenKhacHang_PhieuThu.DisplayMember = "TenKhachHang"
        cmbTenKhacHang_PhieuThu.ValueMember = "idKhachHang"
    End Sub

    Private Sub btnXoaPhieuThu_PhieuThu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaPhieuThu_PhieuThu.Click

        If DataGridViewPhieuThu_PhieuThu.SelectedRows.Count = 0 Then
            Xoaloi()
            Exit Sub
        End If

        If HoiXoa() = Windows.Forms.DialogResult.Yes Then
            Dim pt As New PhieuThuDTO
            If DataGridViewPhieuThu_PhieuThu.SelectedRows.Count = 1 Then
                pt.LayIDKhachHang = DataGridViewPhieuThu_PhieuThu.SelectedRows(0).Cells(1).Value
                pt.LayIdPhieuThu = DataGridViewPhieuThu_PhieuThu.SelectedRows(0).Cells(0).Value

                Dim phieu As New PhieuThuBUS
                phieu.XoaPhieuThu(pt)

                Dim dt As New DataTable

                dt = phieu.LayPhieuThu(pt)
                If dt.Rows.Count > 0 Then
                    DataGridViewPhieuThu_PhieuThu.DataSource = dt
                    DataGridViewPhieuThu_PhieuThu.Columns(1).Visible = False
                Else
                    '  DataGridViewPhieuThu_PhieuThu.DataSource =
                    LoadPhieuThu()
                End If

            End If
        End If
    End Sub

    Private Sub btnLoadPhieuThu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadPhieuThu.Click
        LoadPhieuThu()
    End Sub

    Private Sub btnThemPhieuThu_PhieuThu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemPhieuThu_PhieuThu.Click
        Try

            If txtTienThu_PhieuThu.Text = "" Then

                Exit Sub
            End If
            Dim kh As New KhachHangDTO
            Dim khach As New KhachHangBUS


            Dim phieu As New PhieuThuDTO
            Dim p As New PhieuThuBUS

            phieu.LayIDKhachHang = cmbTenKhacHang_PhieuThu.SelectedValue
            kh.LayIDKhachHang = cmbTenKhacHang_PhieuThu.SelectedValue
            phieu.layNgayThu = DateTimeInput_PhieuThu.Value
            phieu.LayTienThu = txtTienThu_PhieuThu.Text
            p.ThemPhieuThu(phieu)
            ThemThanhCong()

            ' ' ' 'tru nowj khach hàng

            Dim no As Integer
            no = p.LayTienNo(phieu)

            Dim sl As Integer = no - phieu.LayTienThu
            khach.UpDateNo(kh, sl)

            ' khach.LayTienNo(kh)
            LoadKhachHangNo()
            LoadPhieuThu()

            txtTienThu_PhieuThu.Text = String.Empty
        Catch ex As Exception
            If ngon = 0 Then
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        End Try

    End Sub

    Private Sub DataGridViewKhachHang_PhieuThu_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridViewKhachHang_PhieuThu.SelectionChanged

        Try

            cmbTenKhacHang_PhieuThu.DisplayMember = ""
            cmbTenKhacHang_PhieuThu.ValueMember = ""

            If DataGridViewKhachHang_PhieuThu.SelectedRows.Count = 1 Then
                Dim kh As New KhachHangDTO
                Dim khBUS As New KhachHangBUS

                Dim pt As New PhieuThuDTO
                Dim ptBUS As New PhieuThuBUS
                kh.LayIDKhachHang = DataGridViewKhachHang_PhieuThu.SelectedRows(0).Cells(0).Value
                pt.LayIDKhachHang = DataGridViewKhachHang_PhieuThu.SelectedRows(0).Cells(0).Value

                cmbTenKhacHang_PhieuThu.DataSource = khBUS.LayTenKhachHang(kh)
                cmbTenKhacHang_PhieuThu.DisplayMember = "TenKhachHang"
                cmbTenKhacHang_PhieuThu.ValueMember = "idKhachHang"

                txtDiaChi_LapPhieuThu.Text = DataGridViewKhachHang_PhieuThu.SelectedRows(0).Cells(3).Value
                txtSDT_LapPhieuThu.Text = DataGridViewKhachHang_PhieuThu.SelectedRows(0).Cells(2).Value
                txtTienNo_PhieuThu.Text = DataGridViewKhachHang_PhieuThu.SelectedRows(0).Cells(5).Value

                DataGridViewPhieuThu_PhieuThu.DataSource = ptBUS.LayPhieuThu(pt)

                'DataGridViewPhieuThu_PhieuThu.Columns(4).Visible = False ' ' 'cột Xóa ẩn đi
            End If
        Catch ex As Exception

        End Try

    End Sub

#Region "Sự Kiện KeyPress  "

    Private Sub txtSoTienThu_LapPhieuThu_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSDT_LapPhieuThu.KeyPress, txtTienThu_PhieuThu.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtSoDienThoai_LapPhieuThu_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDiaChi_LapPhieuThu.KeyPress, txtTienNo_PhieuThu.KeyPress
        XuLiHam.ChiNhapSo(sender, e)
    End Sub

    Private Sub txtTenKhachHang_LapPhieuThu_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        XuLiHam.KhoangTrang(sender, e)
    End Sub

#End Region

#Region ""


#End Region

#End Region


#Region "Xử Lý Cho Tab Tra Cứu Sách"

    Private Sub tabTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabTraCuu.Click

        Try
            LoadSachTraCuu()
            cmbTheLoai_Search.Enabled = False
            cmbTacGia_Search.Enabled = False

            Dim dt As New DataTable
            ' ' ' ' load The loai len 
            dt = LoadTheLoai()
            cmbTheLoai_Search.DataSource = dt
            cmbTheLoai_Search.DisplayMember = "TenTheLoai"
            cmbTheLoai_Search.ValueMember = "idTheLoai"
            cmbTheLoai_Search.SelectedIndex = -1

            ' ' ' ' load tac giả len
            dt = LoadTacGia()
            cmbTacGia_Search.DataSource = dt
            cmbTacGia_Search.DisplayMember = "TenTacGia"
            cmbTacGia_Search.ValueMember = "idTacGia"
            cmbTacGia_Search.SelectedIndex = -1

            cbTacGia.Checked = False
            cbTheloai.Checked = False
            cbtatCa.Checked = False
        Catch ex As Exception

        End Try

    End Sub

    Private Sub btnClear_TraCuu_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear_TraCuu.Click
        DataGridView.DataSource = Nothing
    End Sub

    Private Sub btnSearch_TraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch_TraCuu.Click

        If txtSearch_TraCuu.Text = "" Then
            Exit Sub
        End If

        Try
            Dim search As New SachBUS
            ' ' ' tim theo tên sách
            DataGridView.DataSource = search.TimTheoTen(txtSearch_TraCuu.Text)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Sub cbtatCa_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbtatCa.CheckedChanged
        If cbtatCa.Checked = True Then
            cbTacGia.Checked = True
            cbTheloai.Checked = True
        Else
            cbTacGia.Checked = False
            cbTheloai.Checked = False
        End If
    End Sub

    Private Sub cbTheloai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbTheloai.CheckedChanged
        If cbTheloai.Checked = True Then
            cmbTheLoai_Search.Enabled = True
        Else
            cmbTheLoai_Search.Enabled = False
        End If
    End Sub

    Private Sub cbTacGia_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbTacGia.CheckedChanged
        If cbTacGia.Checked = True Then
            cmbTacGia_Search.Enabled = True
        Else
            cmbTacGia_Search.Enabled = False
        End If
    End Sub

    Private Sub btnSearchAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchAll.Click
        Dim sach As New SachDTO
        Dim sachbus As New SachBUS

        sach.LayIDTheLoai = cmbTheLoai_Search.SelectedValue
        sach.layTacGia = cmbTacGia_Search.SelectedValue

        ' ' ' 'tim theo tac gia

        If cbTacGia.Checked = True And cbTheloai.Checked = True Then
            DataGridView.DataSource = sachbus.TimTheoTacGia_TheLoai(sach)
            Exit Sub
        End If

        If cbTacGia.Checked = True Then
            DataGridView.DataSource = sachbus.TimTheoTacGia(sach)
        End If

        ' tim theo thể loại
        If cbTheloai.Checked = True Then
            DataGridView.DataSource = sachbus.TimTheoTheLoai(sach)
        End If
    End Sub


    Private Sub txtSearch_TraCuu_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch_TraCuu.TextChanged
        Try
            Dim search As New SachBUS
            ' ' ' tim theo tên sách
            DataGridView.DataSource = search.TimTheoTen(txtSearch_TraCuu.Text)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

#End Region

#Region "Xử lý Cho Tab Báo Cáo Tồn"

#Region "Sự Kiện KeyPress  "

#End Region

#Region "Xử Lý Tab"

    ' Load thang lên ComboBox
    Private Sub tabBaoCaoTon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabBaoCaoTon.Click
        XuLiHam.LoadThang(cboThang_BaoCaoTon)
    End Sub


#End Region

#End Region

#Region "Xử lý Cho Tab Báo Cáo Công Nợ"

#Region "Sự Kiện KeyPress  "

#End Region


#Region "Xử Lý Tab"

    ' Load thang lên ComboBox
    Private Sub tabBaoCaoCongNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tabBaoCaoCongNo.Click
        XuLiHam.LoadThang(cboThang_BaoCaoCongNo)
    End Sub


#End Region

#End Region

#Region "Đa ngôn ngữ"

    ReadOnly culInfoMgr As CommonLibrary


    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
    End Sub

    Public Sub New(ByVal culInfoMgr As CommonLibrary)
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        Me.culInfoMgr = culInfoMgr
        AddHandler culInfoMgr.OnCultureInfoChanges, AddressOf CultureInfiHasChange
    End Sub

    Private Sub CultureInfiHasChange(ByVal sender As Object, ByVal e As EventArgs)
        Try
            SetUI()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub SetUI()
        Dim culInfo As CultureInfo = culInfoMgr.getCultureinfo

        NgonNguNhanVien(culInfo) ' ' ' ' ngôn ngữ cho tab nhân viên
        '' ' ' ' '' ' '' ' ''phần khách hàng xong rôi
        NguNgonKhachHang(culInfo)
        ' ' '' phần tra cứu sách
        NgonNguTraCuuSach(culInfo)

        NgonNguSach(culInfo)

        NgonNguHoaDon(culInfo)

        NgonNguPhieuThu(culInfo)

        NgonNguBaoCaoCongNo(culInfo)
    End Sub

    Public Sub NgonNguNhanVien(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)
        Me.Text = rm.GetString("frmMainText", culInfo)

        LinklblDangXuat.Text = rm.GetString("LinklblDangXuatText", culInfo)
        lblXinhChao.Text = rm.GetString("lblXinhChaoText", culInfo)
        '  '' xưu lí cho tab nhan vien
        tabQuanLynhanVien.Text = rm.GetString("tabQuanLynhanVienText", culInfo)
        lblTimKiem.Text = rm.GetString("lblTimKiemText", culInfo)

        btnTimKiemNhanh_QLNV.Text = rm.GetString("btnTimKiemNhanh_QLNVText", culInfo)
        btnThemNhanVien_QLNV.Text = rm.GetString("btnThemNhanVien_QLNVText", culInfo)
        btnXoaNhanVien_QLNV.Text = rm.GetString("btnXoaNhanVien_QLNVText", culInfo)
        btnCapNhatThongTin_QLNV.Text = rm.GetString("btnCapNhatThongTin_QLNVText", culInfo)

        gbChucnangNV_QLNV.Text = rm.GetString("gbChucnangNV_QLNVText", culInfo)
        lblFone_QLNV.Text = rm.GetString("lblFone_QLNVText", culInfo)
        lblAddress_QLNV.Text = rm.GetString("lblAddress_QLNVText", culInfo)
        lblFullName_QLNV.Text = rm.GetString("lblFullName_QLNVText", culInfo)
        lblGenDer_QLNV.Text = rm.GetString("lblGenDer_QLNVText", culInfo)
        lblLapPass_QLNV.Text = rm.GetString("lblLapPass_QLNVText", culInfo)
        lblPassWord_QLNV.Text = rm.GetString("lblPassWord_QLNVText", culInfo)
        lblUserName_QLNV.Text = rm.GetString("lblUserName_QLNVText", culInfo)
        lblUserType_QLNV.Text = rm.GetString("lblUserType_QLNVText", culInfo)
        gbThongTinNhanVien_QLNV.Text = rm.GetString("gbThongTinNhanVien_QLNVText", culInfo)
        rdiNam.Text = rm.GetString("rdiNamText", culInfo)
        rdoNu.Text = rm.GetString("rdoNuText", culInfo)


        ' ' ' 'dung cho tootip 
        If culInfo.Name = "vi-VN" Then
            btnThemNhanVien_QLNV.Tooltip = "Thêm nhân viên."
            btnXoaNhanVien_QLNV.Tooltip = "Chọn một nhân viên rồi xóa."
            btnCapNhatThongTin_QLNV.Tooltip = "sửa một số thông tin của của nhân viên."
        End If
    End Sub

    Public Sub NguNgonKhachHang(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)

        tabKhachHang.Text = rm.GetString("tabKhachHangText", culInfo)

        btnThemKhachHang.Text = rm.GetString("btnThemKhachHangText", culInfo)
        btnXoaKhachHang.Text = rm.GetString("btnXoaKhachHangText", culInfo)
        btnSuaKhachHang.Text = rm.GetString("btnSuaKhachHangText", culInfo)
        lblTenKhachHang.Text = rm.GetString("lblTenKhachHangText", culInfo)
        lblSDT_KH.Text = rm.GetString("lblSDT_KHText", culInfo)
        lblDiaChiKH.Text = rm.GetString("lblDiaChiKHText", culInfo)
        lblEmail_KH.Text = rm.GetString("lblEmail_KHText", culInfo)
        gbKhachHang.Text = rm.GetString("gbKhachHangText", culInfo)
        lblTienNo_KH.Text = rm.GetString("lblTienNo_KHText", culInfo)
    End Sub

    Public Sub NgonNguTraCuuSach(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)
        Me.Text = rm.GetString("frmMainText", culInfo)

        gbThongTinTraCuu.Text = rm.GetString("gbThongTinTraCuuText", culInfo)
        gbKQTraCuuSach.Text = rm.GetString("gbKQTraCuuSachText", culInfo)

        btnSearchAll.Text() = rm.GetString("btnSearchAllText", culInfo)
        cbTacGia.Text = rm.GetString("cbTacGiaText", culInfo)
        cbTheloai.Text = rm.GetString("cbTheloaiText", culInfo)
        cbtatCa.Text = rm.GetString("cbtatCaText", culInfo)
        btnSearch_TraCuu.Text = rm.GetString("btnSearch_TraCuuText", culInfo)
        lblTenSach_TraCuu.Text = rm.GetString("lblTenSach_TraCuuText", culInfo)
        tabTraCuu.Text = rm.GetString("tabTraCuuText", culInfo)
    End Sub

    Public Sub NgonNguSach(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)

        gbThongTinSach_NhapSach.Text = rm.GetString("gbThongTinSach_NhapSachText", culInfo)

        gbChucNangSach_NhapSach.Text = rm.GetString("gbChucNangSach_NhapSachText", culInfo)
        btnNhapSach_NhapSach.Text = rm.GetString("btnNhapSach_NhapSachText", culInfo)
        btnXoaSach.Text = rm.GetString("btnXoaSachText", culInfo)
        btnSuaSach.Text = rm.GetString("btnSuaSachText", culInfo)
        btnThemSachCu.Text = rm.GetString("btnThemSachCuText", culInfo)

        lblTenSach_NhapSach.Text = rm.GetString("lblTenSach_NhapSachText", culInfo)
        lblDonGia_NhapSach.Text = rm.GetString("lblDonGia_NhapSachText", culInfo)
        lblSoLuong_NhapSach.Text = rm.GetString("lblSoLuong_NhapSachText", culInfo)

        lblTacGia_NhapSach.Text = rm.GetString("lblTacGia_NhapSachText", culInfo)
        lblTheLoai_NhapSach.Text = rm.GetString("lblTheLoai_NhapSachText", culInfo)
        lblNgayNhap_NhapSach.Text = rm.GetString("lblNgayNhap_NhapSachText", culInfo)
        tabNhapSach.Text = rm.GetString("tabNhapSachText", culInfo)

    End Sub

    Public Sub NgonNguHoaDon(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)

        btnThemHoaDon_LapHoaDon.Text = rm.GetString("btnThemHoaDon_LapHoaDonText", culInfo)
        btnSuaHoaDon_LapHoaDon.Text = rm.GetString("btnSuaHoaDon_LapHoaDonText", culInfo)
        btnXoaHoaDon_LapHoaDon.Text = rm.GetString("btnXoaHoaDon_LapHoaDonText", culInfo)
        btnThemChiTiet_HoaDon.Text = rm.GetString("btnThemChiTiet_HoaDonText", culInfo)

        gbChuNangHoaDon_LapHoaDon.Text = rm.GetString("gbChuNangHoaDon_LapHoaDonText", culInfo)

        gbChiTietHoaDon_LapHoaDon.Text = rm.GetString("gbChiTietHoaDon_LapHoaDonText", culInfo)

        gbHoaDon_LapHoaDon.Text = rm.GetString("gbHoaDon_LapHoaDonText", culInfo)

        lblDonGia_LapHoaDon.Text = rm.GetString("lblDonGia_LapHoaDonText", culInfo)
        lblSoLuong_LapHoaDon.Text = rm.GetString("lblSoLuong_LapHoaDonText", culInfo)
        lblTenSach_LapHoaDon.Text = rm.GetString("lblTenSach_LapHoaDonText", culInfo)
        lblTheLoai_LapHoaDon.Text = rm.GetString("lblTheLoai_LapHoaDonText", culInfo)
        lblNgayLapHoaDon_LapHoaDon.Text = rm.GetString("lblNgayLapHoaDon_LapHoaDonText", culInfo)
        lblTenKhachHang_LapHoaDon.Text = rm.GetString("lblTenKhachHang_LapHoaDonText", culInfo)

        tabLapHoaDon.Text = rm.GetString("tabLapHoaDonText", culInfo)

    End Sub


    Public Sub NgonNguPhieuThu(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)

        tabLapPhieuThu.Text = rm.GetString("tabLapPhieuThuText", culInfo)
        btnThemPhieuThu_PhieuThu.Text = rm.GetString("btnThemPhieuThu_PhieuThuText", culInfo)
        btnXoaPhieuThu_PhieuThu.Text = rm.GetString("btnXoaPhieuThu_PhieuThuText", culInfo)
        btnLoadPhieuThu.Text = rm.GetString("btnLoadPhieuThuText", culInfo)
        gbChucNangPhieuThu_LapPhieuThu.Text = rm.GetString("gbChucNangPhieuThu_LapPhieuThuText", culInfo)

        GroupPhieuThu_PhieuThu.Text = rm.GetString("GroupPhieuThu_PhieuThuText", culInfo)
        GroupKhachHang_PhieuThu.Text = rm.GetString("GroupKhachHang_PhieuThuText", culInfo)
        gbThongTinPhieuThu_LapPhieuThu.Text = rm.GetString("gbThongTinPhieuThu_LapPhieuThuText", culInfo)
        lblTongNo_PhieuThu.Text = rm.GetString("lblTongNo_PhieuThuText", culInfo)
        lblTienThu_PhieuThu.Text = rm.GetString("lblTienThu_PhieuThuText", culInfo)
        lblDiaChi_LapPhieuThu.Text = rm.GetString("lblDiaChi_LapPhieuThuText", culInfo)
        lblSDT_LapPhieuThu.Text = rm.GetString("lblSDT_LapPhieuThuText", culInfo)
        lblTenKhachHang_LapPhieuThu.Text = rm.GetString("lblTenKhachHang_LapPhieuThuText", culInfo)
        lblNgayLapPhieu_LapPhieuThu.Text = rm.GetString("lblNgayLapPhieu_LapPhieuThuText", culInfo)
    End Sub


    Public Sub NgonNguBaoCaoCongNo(ByVal culInfo As CultureInfo)
        Dim rm As New ResourceManager("Gui.frmMain", GetType(frmMain).Assembly)

        tabBaoCaoCongNo.Text = rm.GetString("tabBaoCaoCongNoText", culInfo)

        btnTim_BaoCaoCongNo.Text = rm.GetString("btnTim_BaoCaoCongNoText", culInfo)

        lblChonThang_BaoCaoCongNo.Text = rm.GetString("lblChonThang_BaoCaoCongNoText", culInfo)
         End Sub

#End Region

#Region "Các hàm hỗ trợ xóa và cập nhật"
    ' ' ' Thông báo khi chưa chọn dữ liệu để xóa
    Public Sub Xoaloi()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Chưa chọn dữ kiệu để xóa.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            MessageBox.Show("Delete Nothing data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub

    ' ' Thông báo khi chưa chọn dữ liệu để cập nhật
    Public Sub LoiCapNhat()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Chưa chọn dữ liệu để cập nhật.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("Nothing Data update ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    ' ' Thông báo khi cập nhật thành công
    Public Sub CapNhatthanhCong()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Cập Nhật Thành Công.", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            MessageBox.Show(" Success.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub

    Public Sub ThemThanhCong()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Thêm Thành Công.", "Thông Báo", MessageBoxButtons.OK)
        Else
            MessageBox.Show("Add Success.", "Success", MessageBoxButtons.OK)
        End If
    End Sub

    Public Sub XoaThanhCong()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Xóa Thành Công.", "Thông Báo", MessageBoxButtons.OK)
        Else
            MessageBox.Show("Delete Success.", "Success", MessageBoxButtons.OK)
        End If
    End Sub

    Public Function HoiXoa() As DialogResult
        Dim xoa As DialogResult
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            xoa = MessageBox.Show("Bạn Muốn Xóa ?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            Return xoa
        Else
            xoa = MessageBox.Show(" Are You Delete .", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            Return xoa
        End If
    End Function

    Public Function HoiThoat() As DialogResult
        Dim xoa As DialogResult
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            xoa = MessageBox.Show("Bạn Muốn Thoát Chương Trình ?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            Return xoa
        Else
            xoa = MessageBox.Show(" Are You Exit Programming .", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            Return xoa
        End If
    End Function

#End Region

    ' ' ' Load Sách lên DataGriView nhập sách


    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' ' ' dùng cho đa ngôn ngữ
        Try
            SetUI()
            LoadSach()

            Dim loai As Integer = frmLogin.loai
            If loai = 1 Then
                tabQuanLynhanVien.Visible = False
            End If
            lblHienThiTen.Text = frmLogin.strHienThi
            TooTip()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
       
        '      cmbLayGia_HoaDon.Visible = False
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If dangxuat = 0 Then
            If (HoiThoat() = DialogResult.No) Then
                e.Cancel = True
            Else
                frmLogin.Close()
            End If

        End If
    End Sub

    ' ' ' ' '  tootip cho BUTTON
    Public Sub TooTip()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            ' '' Sach
            btnThemTheLoai.Tooltip = "Thêm mới thể mới"
            btnThemTacGia.Tooltip = "Thêm mới tác giả"
            btnThemSachCu.Tooltip = "Thêm sách đã có"
            btnNhapSach_NhapSach.Tooltip = "Nhập Sách"
            btnXoaSach.Tooltip = "Xóa Sách "
            btnSuaSach.Tooltip = "Sửa Thông Tin Sách"

            '''' NhanVien
            btnThemNhanVien_QLNV.Tooltip = "Thêm Nhân Viên"
            btnXoaNhanVien_QLNV.Tooltip = "Xóa Nhân Viên"
            btnCapNhatThongTin_QLNV.Tooltip = "Cập Nhật Thông Tin Nhân Viên"
            btnTimKiemNhanh_QLNV.Tooltip = "Tìm Kiếm Nhanh"

            ''''' Khách Hàng 

            btnThemKhachHang.Tooltip = "Thêm Khách Hàng"
            btnXoaKhachHang.Tooltip = "Xóa Khách Hàng"
            btnSuaKhachHang.Tooltip = "Sữa Thông Tin Khách Hàng"
            btnSuaKhachHang.Tooltip = "Clear Thông Tin Khách Hàng"
        Else
            ' '' Sach
            btnThemTheLoai.Tooltip = "Add New Category"
            btnThemTacGia.Tooltip = "Add new Authors"
            btnThemSachCu.Tooltip = "Add An Existed Book"
            btnNhapSach_NhapSach.Tooltip = "Add Book"
            btnXoaSach.Tooltip = "Delete Book"
            btnSuaSach.Tooltip = "Update Information Book"

            ' ' ' ' NhanVien

        End If
    End Sub

    Dim dangxuat As Integer

    Private Sub LinklblDangXuat_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinklblDangXuat.LinkClicked
        dangxuat = 1
        Me.Close()
        frmLogin.Visible = True
        frmLogin.txtPassWord.Clear()
    End Sub

    Private Sub btnThoat_QLNV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat_QLNV.Click
        Me.Close()
    End Sub

    Private Sub btnTim_BaoCaoCongNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTim_BaoCaoCongNo.Click

        Try
            Dim no As New NoCongBUS
            Dim dt As New DataTable
            dt = no.BaoCaoNoCong(cboThang_BaoCaoCongNo.Text)

            DataGridViewNoCong.DataSource = dt
        Catch ex As Exception
            If ngon = 0 Then
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Else
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        End Try
    End Sub

End Class